//
//  ProjectDetailViewController.m
//  BigToBig
//
//  Created by liuyi on 7/20/16.
//  Copyright © 2016 cn.cloudtp. All rights reserved.
//

#import "ProjectDetailViewController.h"
#import "ProjectDetailModel.h"
#import "UsersNoticeModel.h"
#import "EntrepreneurDetailView.h"
#import "RoadShowDetailHeadView.h"

#import "DetailInfoCell.h"
#import "DetailConceptsCell.h"
#import "DetailMemberCell.h"
#import "DetailMessageCell.h"
#import "DetailFollowerCell.h"
#import "RatingBar.h"
#import "JsTextView.h"
#import "CountDown.h"

@interface ProjectDetailViewController ()
<
UITableViewDelegate,
UITableViewDataSource,
RatingBarDelegate,
UITextViewDelegate,
DetailFollowerCellDelegate
>
@property (nonatomic , retain)EntrepreneurDetailView *entrepreneurDetailView;
@property (nonatomic , retain)RoadShowDetailHeadView *roadShowHeadView;

@property (strong, nonatomic)  CountDown *countDownForBtn;

@property (strong, nonatomic)  CountDown *countDownForLabel;

@property (nonatomic , assign)BOOL ifNoticeProject;
@property (nonatomic , retain)UITableView *mainTableView;
@property (nonatomic , retain)UIView *reviewView;

@property (nonatomic , retain)NSArray *sectionTitleArray;
@property (nonatomic , retain)NSString *info;
@property (nonatomic , retain)NSDictionary *concepts;
@property (nonatomic , retain)NSArray *conceptsKey;
@property (nonatomic , retain)NSMutableArray *usersNoticeModelArr;
@property (nonatomic , strong)ProjectDetailModel *projectDetailModel;

@property (nonatomic , strong)UIButton *focusButton;
@property (nonatomic , retain)JsTextView *textView;

@property (nonatomic , strong)NSString *s1;
@property (nonatomic , strong)NSString *s2;
@property (nonatomic , strong)NSString *s3;
@property (nonatomic , strong)NSString *s4;
@property (nonatomic , strong)NSString *s5;
@property (nonatomic , strong)NSString *comment;
@end


@implementation ProjectDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self LoadUsersNotice];
    [self createData];
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"海水专卖";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    if (self.isRoadShowCreated) {
        ///方法一倒计时测试
        long long startLongLong = 1467713971000;
        long long finishLongLong = 1497713974600;
        
        _countDownForLabel = [[CountDown alloc] init];
        _countDownForBtn = [[CountDown alloc] init];

        [self createViewWhenRoadShowCreated];
        [self startLongLongStartStamp:startLongLong longlongFinishStamp:finishLongLong];
    }
    else{
        [self createView];
    }
    
}
#pragma mark - 创建数据
- (void)createData{
    self.s1 = @"0";
    self.s2 = @"0";
    self.s3 = @"0";
    self.s4 = @"0";
    self.s5 = @"0";
    self.comment = @" ";
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *UID = [userID objectForKey:@"userID"];
    NSLog(@"%@",UID);
    NSDictionary *params = @{@"user_id":UID};
    NSString *urlStr = [NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/project/show_project_info?id=%@&user_id=%@",_project_id,UID];
    [HttpTool textHTMLPostWithURL:urlStr params:params success:^(id json) {
        NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        self.projectDetailModel = [ProjectDetailModel ProjectDetailModelWithDict:dict];
        NSLog(@"%d %@",__LINE__,dict);
        NSLog(@"teaminfo : %@",self.projectDetailModel.team_info);
        self.sectionTitleArray = @[@"项目简介",@"概念阶段",@"团队成员",@"融资信息",@"项目导师",@"项目关注人"];
        self.info = self.projectDetailModel.product_introduction;
        self.conceptsKey = @[@"竞争优势",@"商业模式",@"市场调研"];
        self.concepts = [NSDictionary dictionaryWithObjectsAndKeys:self.projectDetailModel.competitive_edge,self.conceptsKey[0],self.projectDetailModel.business_model,self.conceptsKey[1],self.projectDetailModel.market_research,self.conceptsKey[2],nil];
        
        [self.mainTableView reloadData];
        [self.entrepreneurDetailView.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.bigtobig.com/%@",self.projectDetailModel.project_logo]]];
        
        // 头视图
        self.entrepreneurDetailView.funsLabel.text = [NSString stringWithFormat:@"  粉丝 : %@",self.projectDetailModel.saw_count];
        self.entrepreneurDetailView.focusLabel.text = [NSString stringWithFormat:@"  已关注 : %@",self.projectDetailModel.notice_count];
        NSArray *markArr = [NSMutableArray array];
        markArr = [self.projectDetailModel.areas componentsSeparatedByString:@"|"];
        self.entrepreneurDetailView.markArray = markArr.mutableCopy;
        self.entrepreneurDetailView.titleLabel.text = self.projectDetailModel.project_name;
        self.entrepreneurDetailView.groupLabel.text = self.projectDetailModel.applicant_postion;
        [self.entrepreneurDetailView.markCollectionView reloadData];
        
        // 关注按钮
        self.ifNoticeProject = self.projectDetailModel.if_notice_project.integerValue;
        if (self.ifNoticeProject) {
            self.focusButton.backgroundColor = [UIColor lightGrayColor];
            [self.focusButton setTitle:@"取消关注" forState:UIControlStateNormal];
        }

        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];
}

#pragma mark Load 项目关注人 数据
- (void)LoadUsersNotice{
    self.usersNoticeModelArr = [NSMutableArray array];
    NSDictionary *params = @{@"project_id":self.project_id};
    [HttpTool textHTMLPostWithURL:[NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/notice_project/show_user?project_id=%@&offset=0&limit=10",self.project_id] params:params success:^(id json) {
        NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSArray *usersNoticeArray = [dict objectForKey:@"users_notice"];
        for (NSDictionary *dic in usersNoticeArray) {
            UsersNoticeModel *model = [UsersNoticeModel UsersNoticeModelWithDict:dic];
            [self.usersNoticeModelArr addObject:model];
        }
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
}

- (void)backController:(UIButton *)button{
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createView{
    // 创建头视图
    self.entrepreneurDetailView = [[EntrepreneurDetailView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
       // 主tableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 50) style:UITableViewStyleGrouped];
    self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, -70, 0);
    self.mainTableView.tableHeaderView = self.entrepreneurDetailView;
    [self.view addSubview:_mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.rowHeight = 70;
    self.mainTableView.sectionHeaderHeight = 30;
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    [self.mainTableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:NSStringFromClass([DetailInfoCell class])];
    [self.mainTableView registerClass:[DetailConceptsCell class] forCellReuseIdentifier:NSStringFromClass([DetailConceptsCell class])];
    [self.mainTableView registerClass:[DetailMemberCell class] forCellReuseIdentifier:NSStringFromClass([DetailMemberCell class])];
    [self.mainTableView registerClass:[DetailMessageCell class] forCellReuseIdentifier:NSStringFromClass([DetailMessageCell class])];
    [self.mainTableView registerClass:[DetailFollowerCell class] forCellReuseIdentifier:NSStringFromClass([DetailFollowerCell class])];
    self.mainTableView.bounces = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight - 50, kScreenWidth, 50)];
    [self.view addSubview:footerView];
    
    UIButton *reviewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    reviewButton.frame = CGRectMake(0, 0, kScreenWidth / 2, 50);
    [reviewButton setTitle:@"评分" forState:UIControlStateNormal];
    [reviewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    reviewButton.backgroundColor = [UIColor whiteColor];
    [reviewButton addTarget:self action:@selector(reviewButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:reviewButton];
    
    self.focusButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _focusButton.backgroundColor = COLOR_RGBA(255, 81, 90, 1);
    _focusButton.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 50);
    [_focusButton setTitle:@"关注" forState:UIControlStateNormal];
    [_focusButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_focusButton addTarget:self action:@selector(focusButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:_focusButton];

    
}

- (void)createViewWhenRoadShowCreated{

    // 创建头视图
    self.roadShowHeadView = [[RoadShowDetailHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 265)];
    
    // 主tableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];
    self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, -70, 0);
    self.mainTableView.tableHeaderView = self.roadShowHeadView;
    [self.view addSubview:_mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.rowHeight = 70;
    self.mainTableView.sectionHeaderHeight = 30;
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    [self.mainTableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:NSStringFromClass([DetailInfoCell class])];
    [self.mainTableView registerClass:[DetailConceptsCell class] forCellReuseIdentifier:NSStringFromClass([DetailConceptsCell class])];
    [self.mainTableView registerClass:[DetailMemberCell class] forCellReuseIdentifier:NSStringFromClass([DetailMemberCell class])];
    [self.mainTableView registerClass:[DetailMessageCell class] forCellReuseIdentifier:NSStringFromClass([DetailMessageCell class])];
    [self.mainTableView registerClass:[DetailFollowerCell class] forCellReuseIdentifier:NSStringFromClass([DetailFollowerCell class])];
    self.mainTableView.bounces = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
    self.mainTableView.tableFooterView = footerView;
    
    UIButton *reviewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    reviewButton.frame = CGRectMake(0, 0, kScreenWidth / 3, 50);
    [reviewButton setTitle:@"评分" forState:UIControlStateNormal];
    [reviewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    reviewButton.backgroundColor = [UIColor whiteColor];
    [reviewButton addTarget:self action:@selector(reviewButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:reviewButton];
    
    self.focusButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _focusButton.backgroundColor = [UIColor whiteColor];
    _focusButton.frame = CGRectMake(kScreenWidth / 3, 0, kScreenWidth / 3, 50);
    [_focusButton setTitle:@"关注" forState:UIControlStateNormal];
    [_focusButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_focusButton addTarget:self action:@selector(focusButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:_focusButton];
    UIButton *joinRoadShowButton = [UIButton buttonWithType:UIButtonTypeSystem];
    joinRoadShowButton.backgroundColor = COLOR_RGBA(255, 81, 90, 1);
    joinRoadShowButton.frame = CGRectMake(kScreenWidth / 3 * 2, 0, kScreenWidth / 3, 50);
    [joinRoadShowButton setTitle:@"参与路演" forState:UIControlStateNormal];
    [joinRoadShowButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [joinRoadShowButton addTarget:self action:@selector(joinRoadShowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:joinRoadShowButton];
    
}

#pragma mark - Button 点击方法
- (void)focusButtonAction:(UIButton *)button{
    if (self.isRoadShowCreated) {
        
    }
    else{
        if (self.ifNoticeProject) {
            NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
            NSString *UID = [userID objectForKey:@"userID"];
            MBProgressHUD *HUD1 = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
            HUD1.mode = MBProgressHUDModeIndeterminate;
            NSDictionary *params = @{@"user_id":UID,@"project_id":self.project_id};
            
            [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/notice_project/cancel?" params:params success:^(id json) {
                
                NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
                NSLog(@"%@",dict);
                
                
                if ([[dict objectForKey:@"return_message"] isEqualToString:@"SUCCESS"]) {
                    
                    [UIView animateWithDuration:1.0 animations:^{
                        
                        HUD1.hidden = YES;
                        
                        [NSThread sleepForTimeInterval:1];
                        
                        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                        HUD.labelText = @"取消关注成功";
                        HUD.mode = MBProgressHUDModeText;
                        [HUD hide:YES afterDelay:1.0];
                        self.ifNoticeProject = !self.ifNoticeProject;

                    } completion:^(BOOL finished) {
                        self.focusButton.backgroundColor = COLOR_RGBA(255, 81, 90, 1);
                        [_focusButton setTitle:@"关注" forState:UIControlStateNormal];

                    }];
                    
                    
                }else{
                    
                    HUD1.hidden = YES;
                    [NSThread sleepForTimeInterval:0.5];
                    
                    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                    HUD.labelText = @"系统繁忙,取消关注失败";
                    HUD.mode = MBProgressHUDModeText;
                    [HUD hide:YES afterDelay:1.0];
                }
                
            } failure:^(NSError *error) {
                
                
                
            }];

        }
        else{

            NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
            NSString *UID = [userID objectForKey:@"userID"];
            MBProgressHUD *HUD1 = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
            HUD1.mode = MBProgressHUDModeIndeterminate;
            NSDictionary *params = @{@"user_id":UID,@"project_id":self.project_id};
            
            [HttpTool postWithURL:@"http://61.135.176.43:6080/bigtobig/notice_project/notice?" params:params success:^(id json) {
                
                NSData *data = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:nil];
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
                NSLog(@"%@",dict);
                
                
                if ([[dict objectForKey:@"return_message"] isEqualToString:@"SUCCESS"]) {
                    
                    [UIView animateWithDuration:1.0 animations:^{
                        
                        HUD1.hidden = YES;
                        
                        [NSThread sleepForTimeInterval:1];
                        
                        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                        HUD.labelText = @"关注成功";
                        HUD.mode = MBProgressHUDModeText;
                        [HUD hide:YES afterDelay:1.0];
                        self.ifNoticeProject = !self.ifNoticeProject;

                    } completion:^(BOOL finished) {
                        self.focusButton.backgroundColor = [UIColor lightGrayColor];
                        [_focusButton setTitle:@"取消关注" forState:UIControlStateNormal];
                        
                    }];
                    
                    
                }else{
                    
                    HUD1.hidden = YES;
                    [NSThread sleepForTimeInterval:0.5];
                    
                    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                    HUD.labelText = @"系统繁忙,关注失败";
                    HUD.mode = MBProgressHUDModeText;
                    [HUD hide:YES afterDelay:1.0];
                }
                
            } failure:^(NSError *error) {
                
                
                
            }];

        }
    }
}

- (void)reviewButtonAction:(UIButton *)button{
    self.reviewView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight * 2)];
    self.reviewView.backgroundColor = COLOR_RGBA(25, 26, 27, 0.8);
    [self.view addSubview:self.reviewView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    [self.reviewView addGestureRecognizer:tap];
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(10,120, kScreenWidth - 20, 400)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.reviewView addSubview:backView];

    UILabel *competitivelabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, kScreenWidth / 3 - 30, 40)];
    competitivelabel.text = @"竞  争  力 :";
    competitivelabel.font = [UIFont systemFontOfSize:19];
    competitivelabel.textColor = [UIColor lightGrayColor];
    competitivelabel.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:competitivelabel];
    RatingBar *competitiveBar = [[RatingBar  alloc]initWithFrame:CGRectMake(kScreenWidth / 3 , 15, kScreenWidth / 3 * 2 - 20, 40)];
    competitiveBar.isIndicator = NO;
    [competitiveBar setImageDeselected:@"graystar" halfSelected:@"halfstar" fullSelected:@"yellowstar" andDelegate:self tag:1001];
    [backView addSubview:competitiveBar];
    
    UILabel *innovateLabel = [[UILabel alloc]initWithFrame:CGRectMake(competitivelabel.x, competitivelabel.maxY, competitivelabel.width, competitivelabel.height)];
    innovateLabel.text = @"项目创新 :";
    innovateLabel.font = [UIFont systemFontOfSize:19];
    innovateLabel.textColor = [UIColor lightGrayColor];
    innovateLabel.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:innovateLabel];
    RatingBar *innovateBar = [[RatingBar  alloc]initWithFrame:CGRectMake(competitiveBar.x , competitivelabel.maxY + 10, competitiveBar.width, competitiveBar.height)];
    innovateBar.isIndicator = NO;
    [innovateBar setImageDeselected:@"graystar" halfSelected:@"halfstar" fullSelected:@"yellowstar" andDelegate:self tag:1002];
    [backView addSubview:innovateBar];


    UILabel *fullLabel = [[UILabel alloc]initWithFrame:CGRectMake(innovateLabel.x, innovateLabel.maxY, innovateLabel.width, innovateLabel.height)];
    fullLabel.text = @"完整程度 :";
    fullLabel.font = [UIFont systemFontOfSize:19];
    fullLabel.textColor = [UIColor lightGrayColor];
    fullLabel.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:fullLabel];
    RatingBar *fullBar = [[RatingBar  alloc]initWithFrame:CGRectMake(innovateBar.x , innovateLabel.maxY + 10, innovateBar.width, innovateBar.height)];
    fullBar.isIndicator = NO;
    [fullBar setImageDeselected:@"graystar" halfSelected:@"halfstar" fullSelected:@"yellowstar" andDelegate:self tag:1003];
    [backView addSubview:fullBar];
    
    UILabel *teamLabel = [[UILabel alloc]initWithFrame:CGRectMake(fullLabel.x, fullLabel.maxY, fullLabel.width, fullLabel.height)];
    teamLabel.text = @"团队风采 :";
    teamLabel.font = [UIFont systemFontOfSize:19];
    teamLabel.textColor = [UIColor lightGrayColor];
    teamLabel.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:teamLabel];
    RatingBar *teamBar = [[RatingBar  alloc]initWithFrame:CGRectMake(fullBar.x , fullLabel.maxY + 10, fullBar.width, fullBar.height)];
    teamBar.isIndicator = NO;
    [teamBar setImageDeselected:@"graystar" halfSelected:@"halfstar" fullSelected:@"yellowstar" andDelegate:self tag:1004];
    [backView addSubview:teamBar];
    
    UILabel *marketLabel = [[UILabel alloc]initWithFrame:CGRectMake(teamLabel.x, teamLabel.maxY, teamLabel.width, teamLabel.height)];
    marketLabel.text = @"市场前景 :";
    marketLabel.font = [UIFont systemFontOfSize:19];
    marketLabel.textColor = [UIColor lightGrayColor];
    marketLabel.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:marketLabel];
    RatingBar *marketBar = [[RatingBar  alloc]initWithFrame:CGRectMake(teamBar.x , teamLabel.maxY + 10, teamBar.width, teamBar.height)];
    marketBar.isIndicator = NO;
    [marketBar setImageDeselected:@"graystar" halfSelected:@"halfstar" fullSelected:@"yellowstar" andDelegate:self tag:1005];
    [backView addSubview:marketBar];

    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, marketLabel.maxY + 10, backView.width, 5)];
    lineLabel.backgroundColor = COLOR_RGBA(247, 247, 247, 1);
    [backView addSubview:lineLabel];
    
    JsTextView *textView = [[JsTextView alloc]initWithFrame:CGRectMake(0, lineLabel.maxY + 10, backView.width, backView.height - lineLabel.maxY - 55)];
    self.textView = textView;
    textView.delegate = self;
    [self.view addSubview:textView];
    //1.设置提醒文字
    textView.myPlaceholder=@"  请评价一下这个项目吧~";
    //2.设置提醒文字颜色
    textView.myPlaceholderColor= [UIColor lightGrayColor];
    textView.textAlignment = NSTextAlignmentLeft;
    [backView addSubview:textView];
    
    UIButton *okButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [okButton setTitle:@"确定" forState:UIControlStateNormal];
    [okButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    okButton.frame = CGRectMake(backView.width / 6 * 5, textView.maxY + 15, backView.width / 7, 25);
    okButton.backgroundColor = COLOR_RGBA(39, 219, 160, 1);
    okButton.layer.cornerRadius = 5;
    okButton.layer.masksToBounds = YES;
    [okButton addTarget:self action:@selector(saveReview:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:okButton];
    
    
}


- (void)hide{
    [self.textView resignFirstResponder];
}

- (void)saveReview:(UIButton *)button{
    NSUserDefaults* userID = [NSUserDefaults standardUserDefaults];
    NSString *uid = [userID objectForKey:@"userID"];
    NSString *url = [NSString stringWithFormat:@"http://61.135.176.43:6080/bigtobig/basic/project_comment/add_pc?"];
    NSDictionary *params = @{@"s1":_s1,@"s2":_s2,@"s3":_s3,@"s4":_s4,@"s5":_s5,@"comment":_comment,@"project_id":_project_id,@"user_id":uid};
    [HttpTool postWithURL:url params:params success:^(id json) {
        
        [UIView animateWithDuration:1.0 animations:^{
            if ([[json objectForKey:@"return_message"] isEqualToString:@"B2B_BASIC_PCS_HAS_COMMENT"]) {
                
                MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                HUD.labelText = @"已经评过分了~";
                HUD.mode = MBProgressHUDModeText;
                [HUD hide:YES afterDelay:1.0];
            }
            else{
                MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
                HUD.labelText = @"评分成功";
                HUD.mode = MBProgressHUDModeText;
                [HUD hide:YES afterDelay:1.0];
            }
            
        } completion:^(BOOL finished) {
            NSLog(@"%@",json);

            [self.reviewView removeFromSuperview];

            
        }];

        
    } failure:^(NSError *error) {
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
        HUD.labelText = @"评分失败,请重试!~";
        HUD.mode = MBProgressHUDModeText;
        [HUD hide:YES afterDelay:1.0];
        NSLog(@"%@",error);
        
    }];
    
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    [self moveBackViewWithHeight:-textView.height - 55 ];
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView{
    self.comment = textView.text;

}
- (void)textViewDidEndEditing:(UITextView *)textView{
    [self moveBackViewWithHeight:textView.height + 55];
}

- (void)moveBackViewWithHeight:(CGFloat)height{
    
    [UIView animateWithDuration:0.5 animations:^{
        self.reviewView.y = self.reviewView.frame.origin.y + height;
        
    }];
}

- (void)ratingChanged:(float)newRating WithTag:(NSInteger)tag{

    newRating = (NSInteger)newRating;
    
    if (tag == 1001) {
        self.s1 = [NSString stringWithFormat:@"%ld",(NSInteger)newRating];
    }
    else if (tag == 1002){
        self.s2 = [NSString stringWithFormat:@"%ld",(NSInteger)newRating];
    }
    else if (tag == 1003){
        self.s3 = [NSString stringWithFormat:@"%ld",(NSInteger)newRating];
    }
    else if (tag == 1004){
        self.s4 = [NSString stringWithFormat:@"%ld",(NSInteger)newRating];
    }
    else if (tag == 1005){
        self.s5 = [NSString stringWithFormat:@"%ld",(NSInteger)newRating];
    }
}
- (void)joinRoadShowButtonAction:(UIButton *)button{
    
}



#pragma mark - mainTableView代理方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    else if(section == 1){
        return 3;
    }
    else if (section == 2){
        return 3;
    }
    else if (section == 3){
        return 1;
    }
    else if (section == 4){
        return 2;
    }else if (section == 5){
        return 1;
    }
    else {
        return 0;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth, 30)];
    UILabel *sectionTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.entrepreneurDetailView.maxY, 30)];
    sectionTitle.text = self.sectionTitleArray[section];
    sectionTitle.font = [UIFont systemFontOfSize:15];
    [sectionView addSubview:sectionTitle];
    return sectionView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailInfoCell class]) forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.infoLabel.text = self.info;
        return cell;
    }
    else if (indexPath.section == 1){
        
        DetailConceptsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailConceptsCell class]) forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        NSString *concepts = [self.concepts objectForKey:self.conceptsKey[indexPath.row]];
        cell.conceptsLabel.text = concepts;
        cell.conceptsKeyLabel.text = self.conceptsKey[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if (indexPath.section == 2){
        DetailMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailMemberCell class]) forIndexPath:indexPath];
        cell.titleLabel.text = @"那那那";
        cell.describeLabel.text = @"纯天然的无污染的.大大学生清华北大毕业,一本二本三本创作了什么项目呢哈哈哈,哈哈哈黄飞鸿金";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if (indexPath.section == 3){
        DetailMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailMessageCell class]) forIndexPath:indexPath];
        if (self.projectDetailModel.project_process.integerValue < 2) {
            cell.messageTotalLabel.text = [NSString stringWithFormat:@"0万"];
            cell.messageStockLabel.text = [NSString stringWithFormat:@"0 %"];
            cell.messageRaiseLabel.text = [NSString stringWithFormat:@"0 份"];
            cell.fundUseLabel.text = [NSString stringWithFormat:@"资金用途 : 无"];
            cell.coreRequirementLabel.text = [NSString stringWithFormat:@"资金外核心需求 : 无"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;

        }
        cell.messageTotalLabel.text = [NSString stringWithFormat:@"%@万",self.projectDetailModel.finance_account];
        cell.messageStockLabel.text = [NSString stringWithFormat:@"%@ %",self.projectDetailModel.sell_stock];
        cell.messageRaiseLabel.text = [NSString stringWithFormat:@"%@ 份",self.projectDetailModel.finace_number];
        cell.fundUseLabel.text = [NSString stringWithFormat:@"资金用途 : %@",self.projectDetailModel.fund_use];
        cell.coreRequirementLabel.text = [NSString stringWithFormat:@"资金外核心需求 : %@",self.projectDetailModel.other_needs];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
    else if(indexPath.section == 4){
        DetailMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailMemberCell class]) forIndexPath:indexPath];
        cell.titleLabel.text = @"那那那";
        cell.describeLabel.text = @"纯天然的无污染的.大大学生清华北大毕业,一本二本三本创作了什么项目呢哈哈哈,哈哈哈黄飞鸿金";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
        
    }
    else if (indexPath.section == 5){
        DetailFollowerCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DetailFollowerCell class]) forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.modelArray = [self.usersNoticeModelArr copy];
        cell.followerCellDelegate = self;
        return cell;
    }
    else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        // 计算文字的高度
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
        // 根据文本的内容和文本的字体进行计算高度
        // 参数一:告诉系统,文本显示的最大范围
        CGFloat width = (self.view.frame.size.width - 40);
        CGRect rect = [self.info boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        // 然后把图片的高和文本的高作为返回值返回
        return rect.size.height + 20;
    }
    else if (indexPath.section == 1){
        return 60;
    }
    else if (indexPath.section == 2){
        return 100;
    }
    else if (indexPath.section == 3){
        return 240;
    }
    else if (indexPath.section == 4){
        return 100;
    }
    else if (indexPath.section == 5){
        return 140;
    }
    else{
        return 50;
    }
}

#pragma mark - DetailFollowerCellDelegate  代理方法实现
- (void)pushToFollowerViewWithUserType:(NSString *)userType Model:(NSObject *)selectModel{
    if (userType.integerValue == 1) {
        EntrepreneurDetailMessageController *entrepreneurDetailMessageController = [[EntrepreneurDetailMessageController alloc]init];
        entrepreneurDetailMessageController.model = (UserMessageModel *)selectModel;
        [self.navigationController pushViewController:entrepreneurDetailMessageController animated:YES];
    }
    if (userType.integerValue == 2) {
        InvestorDetailMessageController *investorDetailMessageController = [[InvestorDetailMessageController alloc]init];
        investorDetailMessageController.model = (UserMessageModel *)selectModel;
        [self.navigationController pushViewController:investorDetailMessageController animated:YES];
    }
}

#pragma mark - 创建路演的项目, 路演时间倒计时方法
///此方法用两个时间戳做参数进行倒计时
-(void)startLongLongStartStamp:(long long)strtLL longlongFinishStamp:(long long)finishLL{
    __weak __typeof(self) weakSelf= self;
    
    [_countDownForLabel countDownWithStratTimeStamp:strtLL finishTimeStamp:finishLL completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
        NSLog(@"second : %ld",second);
        [weakSelf refreshUIDay:day hour:hour minute:minute second:second];
    }];
}

-(void)refreshUIDay:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
    if (day==0) {
        self.roadShowHeadView.dayLabel.text = @"0";
    }else{
        self.roadShowHeadView.dayLabel.text = [NSString stringWithFormat:@"%ld",(long)day];
    }
    if (hour<10&&hour) {
        self.roadShowHeadView.hourLabel.text = [NSString stringWithFormat:@"0%ld",(long)hour];
    }else{
        self.roadShowHeadView.hourLabel.text = [NSString stringWithFormat:@"%ld",(long)hour];
    }
    if (minute<10) {
        self.roadShowHeadView.minuteLabel.text = [NSString stringWithFormat:@"0%ld",(long)minute];
    }else{
        self.roadShowHeadView.minuteLabel.text = [NSString stringWithFormat:@"%ld",(long)minute];
    }
    if (second<10) {
        self.roadShowHeadView.secondLabel.text = [NSString stringWithFormat:@"0%ld",(long)second];
    }else{
        self.roadShowHeadView.secondLabel.text = [NSString stringWithFormat:@"%ld",(long)second];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
